home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / +system+ / afcdfind-handlematch.rexx < prev    next >
OS/2 REXX Batch file  |  1999-11-04  |  6KB  |  186 lines

  1. /* $VER: AFCDFind-HandleMatch.rexx 2.0 (3.11.99)
  2. **
  3. ** Support script used by AFCDFind search results
  4. **
  5. ** Usage: AFCDFind-HandleMatch.rexx <pathname>
  6. ** Looks in ENV:AFCDFind_DOpus for config options
  7. **
  8. ** Author: Oliver Roberts
  9. ** E-Mail: oliver.roberts@iname.com
  10. **    WWW: http://www.nanunanu.org/~oliver/
  11. */
  12.  
  13. options results
  14. options failat 21
  15.  
  16. address REXX
  17.  
  18. /* Parse in arguments */
  19. parse arg pathname
  20.  
  21. /* OS 3.5 or DOpus running? */
  22. if ~Show("P","WORKBENCH") then do
  23.    if ~Show("P","DOPUS.1") then EXIT
  24.    else do
  25.       usedopus = 1
  26.       /* WBR mode? */
  27.       address "DOPUS.1" dopus screen
  28.       screen = RESULT
  29.       if (word(screen,1) = 'Workbench') then wbr = 1
  30.       else wbr = 0
  31.    end
  32. end
  33. else usedopus = 0
  34.  
  35. /* Check for required lib */
  36. if ~show('l', 'rexxsupport.library') then do
  37.    call addlib('rexxsupport.library', 0, -30, 0)
  38.    if ~show('l', 'rexxsupport.library') then do
  39.       if (usedopus = 1) then do
  40.          address "DOPUS.1" dopus request '"This feature requires LIBS:rexxsupport.library" OK'
  41.       end
  42.       else do
  43.          address command 'C:RequestChoice AFCDFind "This feature requires LIBS:rexxsupport.library" OK'
  44.       end
  45.       EXIT
  46.    end
  47. end
  48.  
  49. /* Check DOpus version and exit if older than v5.5 */
  50. if (usedopus = 1) then do
  51.    address "DOPUS.1"
  52.    dopus version
  53.    if ( result='RESULT' | translate(result,'.',' ') < 5.1218 ) then do
  54.       dopus request '"This feature requires DOpus v5.5 or greater." OK'
  55.       EXIT
  56.    end
  57. end
  58.  
  59. /* Parse in options in environment variable */
  60. CALL GetEnv('AFCDFind_ViewOpts')
  61. config = RESULT
  62. parse var config . listermode
  63.  
  64. /* Turn AmigaDOS 'Insert Volume' requesters off */
  65. pragma('W','N')
  66.  
  67. /* Determine if the correct CD is inserted, and if not, ask the user to
  68.    insert it */
  69. volume = left(pathname,pos(':',pathname))
  70. DO UNTIL (correctcd = 0 | exists(volume))
  71.   correctcd = 1;
  72.   if (~exists(volume)) then do
  73.       msg = "Please insert Amiga Format CD " || substr(volume,5,length(volume)-5)
  74.       if (usedopus = 1) then do
  75.          if (wbr = 0) then address "DOPUS.1" dopus front
  76.          address "DOPUS.1" dopus request '"'msg'" OK|Cancel'
  77.          correctcd = RC
  78.       end
  79.       else do
  80.          address command 'C:RequestChoice >T:HandleMatch.tmp AFCDFind "'msg'" "OK|Cancel"'
  81.          if OPEN(TMP,'T:HandleMatch.tmp',R) then do
  82.             correctcd = word(readln(TMP),1)
  83.             call close TMP
  84.             delete('T:HandleMatch.tmp')
  85.          end
  86.          else corrected = 0
  87.       end
  88.   end
  89. end
  90.  
  91. /* Do the action if requested CD is available */
  92. if (correctcd = 1 & exists(volume)) then do
  93.    stat = statef(pathname)
  94.    if (WORD(stat,1) = 'DIR') then do
  95.       /* Drawer button: Open the lister */
  96.       /* If drawer has no icon, make sure we are in showall mode */
  97.       drawericon = pathname
  98.       if (right(drawericon,1) = '/') then drawericon = left(drawericon,length(drawericon)-1)
  99.       drawericon = drawericon || '.info'
  100.       hasicon = 1
  101.       if (~exists(drawericon)) then do
  102.          if (find(listermode,'showall') == 0) then listermode = listermode 'showall'
  103.          hasicon = 0
  104.       end
  105.  
  106.       if (usedopus = 1) then do
  107.          /******************************************************************
  108.          ********************** Directory Opus Mode ************************
  109.          ******************************************************************/
  110.          address "DOPUS.1"
  111.          if (wbr = 0) then dopus front
  112.          dopus version
  113.          if (translate(result,'.',' ') < 5.8) then do
  114.             /* Open the lister the messy way - workaround for bug in DOpus */
  115.             lister new pathname
  116.             ourlister = RESULT
  117.             if (word(listermode,1) ~= 'name') then do
  118.                if (pos('showall',listermode) = 0 | pos('default',listermode) ~= 0) then do
  119.                   lister set ourlister mode listermode
  120.                end
  121.             end
  122.          end
  123.          else do
  124.             /* Open the lister the clean way with DOpus 5.8 or higher */
  125.             if (hasicon == 1 & word(listermode,1) ~= 'name') then do
  126.                if (word(listermode,1) ~= 'default') then do
  127.                   lister new mode listermode fromicon pathname
  128.                end
  129.                else do
  130.                   lister new fromicon pathname
  131.                end
  132.             end
  133.             else do
  134.                if (word(listermode,1) ~= 'default') then do
  135.                   lister new mode listermode pathname
  136.                end
  137.                else do
  138.                   lister new pathname
  139.                end
  140.             end
  141.          end
  142.       end
  143.       else do
  144.          /******************************************************************
  145.          ********************** Workbench Mode (OS 3.5) ********************
  146.          ******************************************************************/
  147.          address WORKBENCH
  148.          'WINDOW "'pathname'" OPEN'
  149.          if (word(listermode,1) ~= 'default') then do
  150.             if (word(listermode,1) = 'name') then 'MENU WINDOW "'pathname'" INVOKE WINDOW.VIEWBY.NAME'
  151.             if (word(listermode,1) = 'icon') then 'MENU WINDOW "'pathname'" INVOKE WINDOW.VIEWBY.ICON'
  152.             if (POS('showall',listermode) ~= 0) then 'MENU WINDOW "'pathname'" INVOKE WINDOW.SHOW.ALLFILES'
  153.             else 'MENU WINDOW "'pathname'" INVOKE WINDOW.SHOW.ONLYICONS'
  154.          end
  155.       end
  156.    end
  157.    else do
  158.       /* File button: get DOpus to act on file according to filetypes */
  159.       if (usedopus = 1) then address "DOPUS.1" command doubleclick pathname
  160.    end
  161. end
  162.  
  163. /* Finished */
  164. EXIT
  165.  
  166.  
  167. /* Procedure definitions */
  168.  
  169. /* GetEnv()  return the value of an environmental variable           */
  170. GetEnv: procedure
  171.    /* Arguments:                                                     **
  172.    **   arg(1) := The name of the variable to retrieve               **
  173.    ** Returns     a string                                           */
  174.    /* Use function from rexxarplib if it's available                 */
  175. if show('L', 'rexxarplib.library') then
  176.    return 'GetEnv'(arg(1))
  177.  
  178.    /*  OPEN()  will fail if variable is not defined. Null will be    **
  179.    ** returned in that case                                          */
  180. if open(6Env, 'env:'arg(1), 'R') then do
  181.    EnvVar = readln(6Env)
  182.    call close 6Env
  183. end
  184. else EnvVar = ''
  185. return EnvVar
  186.